import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect:'/index'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/index',
    meta:{
      requireAuth:true
    },
    name: 'index',
    component: () => import('../views/index.vue')
  },
  {
    path: '/news',
    name: 'news',
    component: () => import('../views/news.vue')
  },
  {
    path: '/newsDetails',
    name: 'newsDetails',
    component: () => import('../views/newsDetails.vue')
  },
  {
    path: '/laws',
    name: 'laws',
    component: () => import('../views/laws.vue')
  },
  {
    path: '/lawClass',
    name: 'lawClass',
    component: () => import('../views/lawClass.vue')
  },
  {
    path: '/classDetails',
    name: 'classDetails',
    component: () => import('../views/classDetails.vue')
  },
  {
    path: '/regulations',
    name: 'regulations',
    component: () => import('../views/regulations.vue')
  },
  {
    path: '/opinionNews',
    name: 'opinionNews',
    component: () => import('../views/opinionNews.vue')
  },
  {
    path: '/opinionNewsDetails',
    name: 'opinionNewsDetails',
    component: () => import('../views/opinionNewsDetails.vue')
  },
  {
    path: '/opinionNews_weekDetails',
    name: 'opinionNews_weekDetails',
    component: () => import('../views/opinionNews_weekDetails.vue')
  },
  {
    path: '/videolist',
    name: 'videolist',
    component: () => import('../views/videolist.vue')
  },
  {
    path: '/examList',
    name: 'examList',
    component: () => import('../views/examList.vue')
  },
  {
    path: '/examInfo',
    name: 'examInfo',
    component: () => import('../views/examInfo.vue')
  },

  {
    path: '/toplist',
    name: 'toplist',
    component: () => import('../views/toplist.vue')
  },
  {
    path: '/recordlist',
    name: 'recordlist',
    component: () => import('../views/recordlist.vue')
  },

  {
    path: '/examGoing',
    name: 'examGoing',
    component: () => import('../views/examGoing.vue')
  },
  {
    path: '/examResult',
    name: 'examResult',
    component: () => import('../views/examResult.vue')
  },

  {
    path: '/answerlist',
    name: 'answerlist',
    component: () => import('../views/answerlist.vue')
  },  
]

const router = new VueRouter({
  base:'/',//此处为打包后的文件夹名
  routes,
  mode:'history'
})

export default router

router.beforeEach((to, from, next) => {
  // console.log('topath=====>',to.path)
  let customertoken = localStorage.getItem('customertoken')
    // console.log('customertoken=====>',customertoken)
    if (!customertoken && to.path !== '/login') {
      // 若本地token不存在,则任意路由跳转的时候,重定向至login 登陆页面
      next('/login')
    } else {
      next()
    }
})

